package designprinciples.opencloseprinciple;

import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * @program: MyTank
 * @description:
 * @author: 王术平
 * @create: 2021-01-23 19:15
 **/
public class Client02 {
    public static void main(String[] args) {
        Person02 p = new Person02("小明");
        p.feed(new Dog02());
        p.feed(new Cat());
    }
}

class Dog02 implements Animal {
    @Override
    public void eat(Person02 p) {
        System.out.println(p.getName() + "正在喂狗吃屎");
    }
}


class Cat implements Animal {
    @Override
    public void eat(Person02 p) {
        System.out.println(p.getName() + "正在喂猫吃鱼");
    }
}

@AllArgsConstructor
@Data
class Person02 {
    private String name;
    public void feed(Animal dog) {
        dog.eat(this);
    }
}


interface Animal {
    void eat(Person02 p);
}
